package com.example.module_device.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.example.module_device.databinding.DeviceItemBinding
import com.example.module_device.model.DeviceEntityItem

class DeviceAdapter : RecyclerView.Adapter<DeviceAdapter.VH>() {
    var mList = mutableListOf<DeviceEntityItem>()
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH {
        val binding = DeviceItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
        return VH(binding)
    }

    override fun getItemCount(): Int {
        return mList.size
    }

    override fun onBindViewHolder(holder: VH, position: Int) {
        holder.binding.post = mList[position]
    }

    fun setList(listItem : MutableList<DeviceEntityItem>) {
        mList.clear()
        mList.addAll(listItem)
        mList.reverse()
        notifyDataSetChanged()
    }

    inner class VH(val binding : DeviceItemBinding) : ViewHolder(binding.root)

}
